
const { createRouter } = nfUICore

// 定义路由

const url = window.__basrUrl

// const home = () => myImport('views/home')
import home from '../views/home.js'

const router = createRouter({
  /**
   * 基础路径
   */
  baseUrl: url.substring(0,url.length-1),
  /**
   * 首页
   */
  home: home,

  menus: [
    {
      menuId: '11', title: '状态', path: 'state', icon: '',
      component: () => myImport('views/state/state1')
    },
    {
      menuId: '12', title: 'ui', path: 'ui', icon: '',
      component: () => myImport('views/ui/ui-elp')
    },
    {
      menuId: '13', title: 'elp表单', path: 'elp-test', icon: '',
      component: () => myImport('views/elp/form-test')
    }
  ]
})


router.refresh = () => {
  console.log('覆盖原生的刷新')
  router.isRefresh = true
  const search = window.location.search
  const path = search.replace('?url=src','')

  if (path === '/' || path === router.baseUrl) {
    // 首页
  } else {
    const tmp = path.replace(router.baseUrl, '')
    // 根据URL加载组件
    Object.keys(router.menuList).forEach(key => {
      const _menu = router.menuList[key]
      if (_menu.paths === tmp) {
        router.currentRoute.key = key
        document.title = _menu.title + '-' + router.baseTitle
        let _url = router.baseUrl + tmp
        // 设置url地址
        window.history.pushState(null, null, _url)
      }
    })
  }
}

export default router
